/**
 * 
 */
package Stubs;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Random;

import Exceptions.InvalidRideId;
import Exceptions.CentralComputerExceptions.ChildAgeDoesntMatch;
import Exceptions.CentralComputerExceptions.ChildDoesntHaveTicket;
import Exceptions.CentralComputerExceptions.ChildHeightDoesntMatch;
import Exceptions.CentralComputerExceptions.ChildIDDoesntExist;
import RideExceptions.ChildNotInRideException;

import sourceFiles.ChildEntry;
import sourceFiles.ETicket;
import sourceFiles.ExtremeRideEntry;
import sourceFiles.GuardianEntry;
import sourceFiles.ICentralComputer;
import sourceFiles.IRide;
import sourceFiles.RegularRideEntry;
import sourceFiles.Ride;
import sourceFiles.RideEntry;
import sourceFiles.RideState;
import sourceFiles.SupervisorStation;
import sourceFiles.XMLRidesParser;

/**
 * @author LASO-Team
 *
 */
public class CentralComputerStub implements ICentralComputer {

	private static final int TEST_SIZE = 10;
	private static final int MAX_RANDOM = 100;

	private LinkedList<Ride> rides;
	private LinkedList<RideEntry> entries;
	private Integer rideID = 1;
	private final Integer updatedRideID = 301227062;
	private LinkedList<ChildEntry> children;
	private LinkedList<Integer> minAge, minHeight, maxCapacity;

	/**
	 * @param rides
	 * @param rideID
	 */
	public CentralComputerStub() {
		super();
		rides = new LinkedList<Ride>();
		entries = new LinkedList<RideEntry>();
		children = new LinkedList<ChildEntry>();
	}

	/**
	 * @return the testRide
	 */
	public LinkedList<Ride> getRides() {
		return rides;
	}

	/**
	 * @return the entries
	 */
	public LinkedList<RideEntry> getEntries() {
		return entries;
	}

	/**
	 * @return the field children
	 */
	public LinkedList<ChildEntry> getChildren() {
		return children;
	}

	/**
	 * @return the rideID
	 */
	public Integer getRideID() {
		return rideID;
	}

	@Override
	public Integer createRide(String rideName, Boolean isExtremeRide,
			Integer maxCapacity, Integer minAge, Integer minHeight) {
		
		
		rides.add(new Ride(rideID, maxCapacity, minAge, minHeight, rideName,
				this));
		Random randomPrice = new Random();
		if (isExtremeRide) {
			entries.add(new ExtremeRideEntry(rideName, rideID, randomPrice
					.nextDouble() * 10.0));
		} else {
			entries.add(new RegularRideEntry(rideName, rideID, randomPrice
					.nextDouble() * 10.0));
		}
		rideID = rideID + 1;
		return rideID;
	}

	@Override
	public void updateRide(Integer rideID, Integer maxCapacity, Integer minAge,
			Integer minHeight) throws InvalidRideId {
		if (rideID.equals(updatedRideID)) {
			rides.add(new Ride(updatedRideID, maxCapacity, minAge, minHeight,
					"blah", this));
		} else {
			throw new InvalidRideId();
		}

	}

	@Override
	public String addGuardian(Integer guardianID, Integer billingInfo) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void addChildToGuardian(Integer guardianID, Integer childID,
			Integer age, Integer height) {
		// TODO Auto-generated method stub

	}

	@Override
	public void connectGuardian(Integer userID, String userPassword) {
		// TODO Auto-generated method stub

	}

	@Override
	public void buyingProcess(Integer rideID, Integer guardianID,
			Integer childID) {
		// TODO Auto-generated method stub

	}

	@Override
	public void performBilling(Double ridePrice, Integer billingInfo) {
		// TODO Auto-generated method stub

	}

	@Override
	public void cancelAcquisition(Integer rideID, Integer guardianID,
			Integer childID) {
		// TODO Auto-generated method stub

	}

	@Override
	public void validateChildForRide(Integer rideID, Integer childID)
			throws ChildIDDoesntExist, ChildAgeDoesntMatch,
			ChildHeightDoesntMatch, ChildDoesntHaveTicket {
		// TODO Auto-generated method stub
		Random rand = new Random();

		for (Iterator<ChildEntry> iterator = children.iterator(); iterator
				.hasNext();) {
			ChildEntry child = (ChildEntry) iterator.next();
			if (child.getID() == childID) {
				if (child.getAge() < rides.get(rand.nextInt(TEST_SIZE))
						.getMinimumAge()) {
					throw new ChildAgeDoesntMatch();
				}
				else if (child.getHeight() < rides.get(rand.nextInt(TEST_SIZE))
						.getMinimumHeight()) {
					throw new ChildHeightDoesntMatch();
				}
				else if (childID > MAX_RANDOM) {
					throw new ChildDoesntHaveTicket();
				}
				return;
			}
		}
		throw new ChildIDDoesntExist();
	}

	@Override
	public Map<Integer, Integer> retrieveChildrenLocation(Integer guardinID) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ETicket retrieveChildETicket(Integer childID) {
		// TODO Auto-generated method stub
		return null;
	}



	@Override
	public XMLRidesParser getParser() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setParser(XMLRidesParser parser) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public HashMap<Integer, Integer> getTicketsSold() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setTicketsSold(HashMap<Integer, Integer> ticketsSold) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public SupervisorStation getSupervisorStation() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setSupervisorStation(SupervisorStation supervisorStation) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public LinkedList<GuardianEntry> getGuardiansList() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setGuardiansList(LinkedList<GuardianEntry> guardiansList) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public LinkedList<ChildEntry> getChildrenList() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setChildrenList(LinkedList<ChildEntry> childrenList) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public LinkedList<IRide> getRidesList() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setRidesList(LinkedList<IRide> ridesList) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public LinkedList<RideEntry> getRidesCatalog() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setRidesCatalog(LinkedList<RideEntry> ridesCatalog) {
		// TODO Auto-generated method stub
		
	}

}
